package one.four.sixteen;

import java.util.Arrays;

public class Nearest {

	public static double[] nearest(double[] a) {
		Arrays.sort(a);
		int idx = -1;
		double n = Double.MAX_VALUE;
		double t;
		for (int i = 0; i < a.length - 1; i++) {
			t = Math.abs(a[i] - a[i + 1]);
			if (t < n) {
				n = t;
				idx = i;
			}
		}
		// System.out.println(n);
		System.out.println(a[idx] + "," + a[idx + 1]);
		double[] r = { a[idx], a[idx + 1] };
		return r;
	}

	public static void main(String[] args) {
		double[] a = { 0.1, -0.4, 1.5, 0.8 };
		double[] r = nearest(a);
		System.out.println(Arrays.toString(r));
	}

}
